package collection;

import generic.Person;
import junit.framework.TestCase;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhangxin
 * @date 2020/9/28
 */
public class ListTest extends TestCase {
    private List<Person> list;
    private Person person;

    public ListTest() {
        person = new Person();
        list = new ArrayList<>();
    }

    public ListTest(Person person) {
        this.person = person;
        list = new ArrayList<>();
    }

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();

        for (int i = 0; i < 9; i++) {
            list.add("java");
        }
        list.add("java");
        list.add("java4");
        list.add("java3");
        list.add("java2");
        //
        //list.forEach(e->{
        //    list.remove("java2");
        //});
        //list.remove("java2");
        //list.remove("java4");
        list.forEach(System.out::println);
    }

    public void testList() {

        int a = 10;
        if (a++ > 10) {
            System.out.println(1);
        }

        // 00000 01
        // 00000 10
        // 00000 11
        System.out.println(1 ^ 2);

    }


    @Test
    public void testRemoveAll() {
        List<String> list = new ArrayList<>(10);
        for (int i = 0; i < 9; i++) {
            list.add("java" + i);
        }

        list.removeAll(Arrays.asList("java3"));


        String[] strings = list.toArray(new String[0]);

        for (String string : strings) {
            System.out.println(string);
        }
    }

    @Test
    public void testAtoInteger() {
        AtomicInteger atomicInteger = new AtomicInteger();
        int andIncrement = atomicInteger.getAndIncrement();

        System.out.println(andIncrement);

        System.out.println(atomicInteger);

        System.out.println("decre:" + atomicInteger.getAndDecrement());
        System.out.println("atoIn:" + atomicInteger);
    }

    @Test
    public void testLinkedQueue() throws InterruptedException {
        LinkedBlockingQueue<Object> objects = new LinkedBlockingQueue<>();

        objects.add("java");

        objects.take();
    }
}
